#include "mylib.h"
#include <stdio.h>
#include "a.h"

static int test1(lua_State* L)
{
	printf("test1\n");
	return 0;
}

static int TestA(lua_State* L)
{
	int a = (int)luaL_checkinteger(L, -1);
	ATest(a);
	return 0;
}

static int testSum(lua_State* L)
{
	int n = lua_gettop(L);
	printf("top=%d\n", n);
	double sum = 0;
	for (int i = 1; i <= n; ++i)
	{
		if (lua_isnumber(L, i))
		{
			double v = lua_tonumber(L, i);
			printf("v = %f\n", v);
			sum += v;

		}
	}
	lua_pushnumber(L, sum);
	return 1;
}

static const struct luaL_Reg myLib[] = 
{
	{"test1", test1},
	{"testSum", testSum},
	{"testa", TestA},
	{NULL, NULL}
};

int luaopen_mylib(lua_State* L)
{
	luaL_newlib(L, myLib);
	return 1;
}
